package com.wanhai.itm.services;

import com.wanhai.ejb.dbhandler.DBHandlerLocal;
import com.wanhai.util.RecordProcessBean;
import java.util.ArrayList;
import java.util.List;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

/**
 *
 * @author Richard Shih
 */
public class DefaultDataService<T extends RecordProcessBean> {

    String _DataSource = null;
    Log _Logger = LogFactory.getLog(getClass());

    public DefaultDataService() {
        init();
    }

    public List<T> find(T condition) throws Exception {
        ArrayList<T> rtnValues = new ArrayList<T>();
        DBHandlerLocal handler = getDBHandler();
        rtnValues = handler.query(condition);
        return rtnValues;
    }

    public int insert(T target) throws Exception {
        return getDBHandler().insert(target);
    }

    public int update(T target) throws Exception {
        return getDBHandler().update(target);
    }

    private void init() {
        _DataSource = "java:/OraWhl2DS";
    }

    private DBHandlerLocal getDBHandler() {
        DBHandlerLocal handler = new DBHandlerLocal();
        handler.setConnection(_DataSource);
        handler.setQuerySize(-1);
        return handler;
    }
}
